*Table A.8: Descriptive statistics of anthropometric measurements at baseline
cd ""

use "master_data_adults_child_s13456_shared.dta", clear 

drop meal_control snack_control
gen meal_control=1 if treatment==2
replace meal_control=0 if treatment==1
tab meal_control

gen snack_control=1 if treatment==3
replace snack_control=0 if treatment==1
tab snack_control


drop if type_id=="X" // **Dropping newborns born during the three years of study
drop if id=="3885553B" //**error in the id number and empty data
drop if id=="3885553G" //**error in the id number and empty data
replace treatment=2 if id=="38855553B" //**retrieving the correct treatment for this id
replace treatment=2 if id=="38855553G" //**retrieving the correct treatment for this id
drop if id=="101aa22c" //**this id does not exist
drop if id=="27655663" //**outlier on many measurements



***BMI****
//gen an obesity variable//
*lab define bmi ///
*-1 "Underweight" ///	
*0 "Normal weight" ///	
*1 "Overweight" ///
*2 "Obese", replace
gen obese_var=1 if bmi_cat==2
replace obese_var=0 if obese_var==. & bmi_cat!=.

gen overw_obese=1 if bmi_cat==2 | bmi_cat==1
replace overw_obese=0 if overw_obese==. & bmi_cat!=.

***percentile in children
gen pzheight=normal(zht)
gen pzweight=normal(zwt)

*Calculate z-scores for BMI
egen gendermax=max(gender), by(id_nb)
ge sex=(gendermax==1) 
replace sex=. if gendermax==.

drop zbmi pzbmi
egen zbmi = zanthro(bmi,ba,UK), xvar(months) gender(sex) gencode(male=1, female=0) ageunit(month)
gen pzbmi=normal(zbmi)

ge uwgt_child=(pzbmi<=0.02)
replace uwgt_child=. if pzbmi==.

ge normalw_child=(pzbmi>0.02 & pzbmi<0.85)
replace normalw_child=. if pzbmi==.

ge overw_child=(pzbmi>=0.85 & pzbmi<0.91)
replace overw_child=. if pzbmi==.  

ge overw_obese_child=(pzbmi>=0.85)
replace overw_obese_child=. if pzbmi==.  

ge obesew_child=(pzbmi>=0.91)
replace obesew_child=. if pzbmi==.

drop bmi_cat_child
ge bmi_cat_child=.
replace bmi_cat_child=-1 if uwgt_child==1
replace bmi_cat_child=0 if normalw_child==1
replace bmi_cat_child=1 if overw_child==1
replace bmi_cat_child=2 if obesew_child==1


**PANEL A Children
bys treatment: su pzbmi if child==1 & session==1
ranksum pzbmi if child==1 & session==1, by(meal_control) 
ranksum pzbmi if child==1 & session==1, by(snack_control) 

bys treatment: su zbmi if child==1 & session==1
ranksum zbmi if child==1 & session==1, by(meal_control) 
ranksum zbmi if child==1 & session==1, by(snack_control) 

bys treatment: tab bmi_cat_child if child==1 & session==1
ksmirnov bmi_cat_child if session==1 & child==1, by(meal_control) 
ksmirnov bmi_cat_child if session==1 & child==1, by(snack_control) 
 
**PANEL B Adults
bys treatment: su bmi if child==0 & session==1
ranksum bmi if session==1 & child==0 & session==1, by(meal_control)  //ns
ranksum bmi if session==1 & child==0 & session==1, by(snack_control)  //ns
 
bys treatment: su bmi if gender==1 & child==0 & session==1
ranksum bmi if session==1 & gender==1 & child==0 , by(meal_control)  //ns
ranksum bmi if session==1 & gender==1 & child==0, by(snack_control)  //ns
 
bys treatment: su bmi if gender==2 & child==0 & session==1 & (pregnant==2 | pregnant==.)
ranksum bmi if session==1 & gender==2 & child==0 & (pregnant==2 | pregnant==.), by(meal_control)
ranksum bmi if session==1 & gender==2 & child==0 & (pregnant==2 | pregnant==.), by(snack_control)

bys treatment: tab bmi_cat if child==0 & session==1 & (pregnant==2 | pregnant==.)
ksmirnov bmi_cat  if  session==1  & child==0  & (pregnant==2 | pregnant==.), by(meal_control)
ksmirnov bmi_cat  if  session==1  & child==0  & (pregnant==2 | pregnant==.), by(snack_control)  



